import java.util.function.BinaryOperator;
import java.util.stream.Stream;

public class Test {
    public static void main(String[] args) {
        int sum = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9).reduce(0, (pre, curent) -> pre + curent);
        System.out.println(sum);
        
        BinaryOperator<Integer> fn = (pre, current) -> {
            if (current % 2 == 0) {
                return pre + current;
            } else {
                return pre;
            }
        };
        int sum2 = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9).reduce(0, fn);
        System.out.println(sum2);
    }
}
